#!/bin/bash

###############################################################################
# Copyright 2024 cong. All rights reserved.
###############################################################################

function get_log_name() {
  local date; date=$(date +%Y%m%d-%H%M%S-%N)
  mkdir -p "${ROOT_DIR}/log"
  local log_file
  log_file="${ROOT_DIR}/log/$1_${date}.out"
  # Make relative symlink for ease of use
  ln -sf "$log_file" "${ROOT_DIR}/log/$1.out"
  echo "$log_file"
}

source setup.bash

while true
do
    PIDS=`ps -ef | grep record_node | grep -v grep | awk '{print $2}'`
    if [ "$PIDS" != "" ]; then
        echo "record_node is runing!"
    else
        /bin/bash ${ROOT_DIR}/bin/record_node > "$(get_log_name "record_node")" 2>&1 &
        echo "record_node isn't exit,start now..."
    fi

    sleep 5
done
